<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="path" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>校园论坛 - 相思湖学院</title>
<link rel="shortcut icon" href="static/image/logo_little.png">
<link rel="stylesheet" type="text/css" href="static/css/bootstrap.css" >
<link rel="stylesheet" type="text/css" href="static/css/top.css" >
<link rel="stylesheet" type="text/css" href="static/css/forum.css" >
</head>
<body>
	<div class="top">
		<img class="logo" alt="相思湖学院论坛" src="static/image/logo.png">
		<form action="search" method="post" onsubmit="return isEmpty()">
			<input  id="search" name="search" type="text" value="" placeholder="请输入搜索内容">
		    <button type="submit" class="submit">搜索</button>
		</form>
		<script type="text/javascript">
			function isEmpty() {
				if(document.getElementById("search").value == "") {
					$('<div>').appendTo('body').addClass('alert alert-info').html("请输入搜索内容").show().delay(1500).fadeOut();
					return false;
				}
				return true;
			}
		</script>
		<c:if test="${user != null }">
			<div class="user">
				<span><a style="font-weight: 800;color: black;" href="userinfo">${user.username }</a></span>
				<span>|</span>
				<div class="dropdown" style="display: inline-block;">
					<a data-toggle="dropdown" class="dropdown-toggle" href="#">我的<strong class="caret"></strong></a>
					<ul class="dropdown-menu">
						<li><a href="user?id=${user.id }&selected=mytopic">帖子</a></li>
						<!-- <li><a href="#">收藏</a></li>
						<li><a href="#">好友</a></li> -->
					</ul>
				</div>
				<span>|</span>
				<span><a href="userinfo">设置</a></span>
				<!-- <span>|</span>
				<span><a href="#">消息</a></span> -->
				<span>|</span>
				<div class="dropdown" style="display: inline-block;">
					<a data-toggle="dropdown" class="dropdown-toggle" href="#">提醒<strong class="caret"></strong></a>
					<ul class="dropdown-menu">
						<li><a href="notice">消息</a></li>
						<!-- <li><a href="#">新听众</a></li> -->
					</ul>
				</div>
				<span>|</span>
				<span><a href="exit">退出</a></span>
				<c:if test="${user.avatar != null && user.avatar != '' }">
					<img class="avatar" src="${user.avatar }">
				</c:if>
				<c:if test="${user.avatar == null || user.avatar == '' }">
					<img class="avatar" src="static/image/noavatar.jpg">
				</c:if>
			</div>
		</c:if>
		<c:if test="${user == null }">
			<div class="visitor">
				<a href="ps.login">登陆</a>
				<a href="${path }/register.jsp">注册</a>
			</div>
		</c:if>
	</div>
	
	<div class="contral">
		<div class="title">
			<a href="forum" class="nvhm" title="首页"></a>
			<em></em>
			<a href="forum">论坛</a>
			<c:if test="${user.role == 2 }">
				<a class="submit" style="padding: 5px 10px; margin-left: 20px;" href="javascript:;" onclick="showPartition('0')">添加分区</a>
			</c:if>
			
		</div>
		<div class="head">
		</div>
		<div class="mn">
			<c:forEach items="${partitionList }" var="p">
				<%-- <c:if test="${p.name == '校园服务' }">
					<div class="pt${p.id }">
						<div class="pt_h">
							<h2><a href="javascript:void(0);" onclick="pt_bs('pt_bs${p.id}')" title="收起/展开">${p.name }</a></h2>
						</div>
						<div id="pt_bs${p.id }" style="margin-left: 35px; padding-top: 10px;">
							<c:if test="${p.blockList != null }">
								<c:forEach items="${p.blockList }" var="b">
									<div class="pt_b">
										<a href="#" target="_blank" style="display: block; margin-left: 12px;">
											<img src="static/image/common_25_icon.png">
										</a>
										<a href="#" target="_blank" style="display: block; text-align: center;"><strong>${b.name }</strong></a>
									</div>
								</c:forEach>
							</c:if>
						</div>
					</div>
				</c:if> --%>
				<%-- <c:if test="${p.name != '校园服务' }"> --%>
					<div class="pt">
						<div class="pt_h">
							<c:if test="${user.role == 2 }">
								<a class="pt_a" href="javascript:;" onclick="return warning('deletePartition?id=${p.id}')">删除分区</a>
								<a class="pt_a" href="javascript:;" onclick="showPartition('${p.id}', '${p.name }')">修改分区</a>
								<a class="pt_a" href="javascript:;" onclick="showBlock('0', '${p.id}')">添加版块</a>
							</c:if>
							<h2>
								<a href="javascript:void(0);" onclick="pt_bs('pt_bs${p.id}')" title="收起/展开">${p.name }</a>
							</h2>
						</div>
						<div id="pt_bs${p.id }" style="padding-top: 10px;">
							<c:if test="${p.blockList != null }">
								<c:forEach items="${p.blockList }" var="b" varStatus="status">
									<div class="pt_b">
										<a href="block?bid=${b.id }" target="_blank">
											<img src="static/image/common_25_icon.png">
										</a>
										<span>
											<a href="block?bid=${b.id }" target="_blank">
												<strong>${b.name }</strong>
											</a>
											<c:if test="${user.role == 2 }">
												<a class="pt_a" style="color: #3583ba; float: right;" href="javascript:;" onclick="return warning('deleteBlock?id=${b.id}')">删除版块</a>
												<a class="pt_a" style="color: #3583ba; float: right; margin-right: 5px;" href="javascript:;" onclick="showBlock('${b.id }', '${p.id}', '${b.name }')">修改版块</a>
											</c:if>
										</span>
										<c:if test="${b.topic != null }">
											<span><a href="ps.topic?id=${b.topic.id }">${b.topic.title }</a></span>
											<span>by：<a href="user?id=${b.topic.user.id }">${b.topic.user.username }</a>&nbsp;[${b.topic.updatetime }]</span>
										</c:if>
										<c:if test="${b.topic == null }">
											<span>暂无发帖</span>
											<span style="height: 18px;"></span>
										</c:if>
									</div>
									<c:if test="${(status.index+1) % 3 == 0 }">
										<hr style="border-top:1px silver dashed;">
									</c:if>
								</c:forEach>
							</c:if>
						</div>
					</div>
				<%-- </c:if> --%>
			</c:forEach>
		</div>
	</div>
	
	<div id="partition" class="hideWindow" style="display: none;">
		<span><strong id="partition_title" style="color: #369; font-size: 18px;">添加分区</strong></span>
		<span style="float: right;"><a class="close" title="关闭" onclick="hideWindow('partition')">关闭</a></span><br/>
		<form id="partition_form" action="">
			<input type="hidden" id="partition_id" name="id">
			分区名：<input style="margin-left: 14px;" type="text" id="partition_name" name="name"><br>
			<input type="submit" class="submit" value="提交">
		</form>
	</div>
	<div id="block" class="hideWindow" style="display: none;">
		<span><strong id="block_title" style="color: #369; font-size: 18px;">添加版块</strong></span>
		<span style="float: right;"><a class="close" title="关闭" onclick="hideWindow('block')">关闭</a></span><br/>
		<form id="block_form" action="">
			<input type="hidden" id="block_id" name="id">
			所属分区：<select id="block_pid" name="pid">
				<c:forEach items="${partitionList }" var="p">
					<option value="${p.id }">${p.name }</option>
				</c:forEach>
			</select><br>
			版块名：<input style="margin-left: 14px;" type="text" id="block_name" name="name">
			<input style="margin-left: 70px;" type="submit" class="submit" value="提交">
		</form>
	</div>
	<script type="text/javascript">
		function showPartition(id, name) {
			if(id == 0) {
				document.getElementById("partition_title").innerHTML = "添加分区";
				document.getElementById("partition_id").value = "";
				document.getElementById('partition_form').action = "insertPartition";
			} else {
				document.getElementById("partition_title").innerHTML = "修改分区";
				document.getElementById('partition_id').value = id;
				document.getElementById('partition_name').value = name;
				document.getElementById('partition_form').action = "updatePartition";
			}
			document.getElementById("partition").style.display = "";
		}
		function showBlock(id, pid, name) {
			document.getElementById("block_pid").value = pid;
			if(id == 0) {
				document.getElementById("block_title").innerHTML = "添加版块";
				document.getElementById("block_id").value = "";
				document.getElementById('block_form').action = "insertBlock";
			} else {
				document.getElementById("block_title").innerHTML = "修改版块";
				document.getElementById('block_id').value = id;
				document.getElementById('block_name').value = name;
				document.getElementById('block_form').action = "updateBlock";
			}
			document.getElementById("block").style.display = "";
		}
		function hideWindow(id) {
			document.getElementById(id).style.display = "none";
		}
	</script>
	
</body>
<script type="text/javascript" src="static/js/jquery-3.3.1.js"></script>
<script type="text/javascript" src="static/js/bootstrap.js"></script>
<script type="text/javascript">
	function pt_bs(id) {
		if(document.getElementById(id).style.display == "none") {
			document.getElementById(id).style.display = "";
		}else {
			document.getElementById(id).style.display = "none";
		}
	}
	
	function warning(url){
	    if(confirm('确定要删除吗') == true){
	    	location.href = url;
	    	return true;
	    }else{
	    	return false;
	    }
	}
	
</script>
</html>